package 华为OD机试真题2023.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ22_区块链文件转储系统 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/进阶题/input/22.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        int SataSize = in.nextInt();
        in.nextLine(); // 吸收回车
        String[] sArray = in.nextLine().split(" ");
        int[] nums = new int[sArray.length];
        for (int i = 0; i < sArray.length; i++) {
            nums[i] = Integer.parseInt(sArray[i]);
        }
        int slow = 0, fast = 0;
        int tmpSize = 0, maxSize = 0;
        while (fast < nums.length) {
            tmpSize += nums[fast];
            while (tmpSize > SataSize) {
                tmpSize -= nums[slow];
                slow++;
            }
            maxSize = Math.max(maxSize, tmpSize);
            fast++;
        }
        System.out.println(maxSize);
    }
}
